package com.lagou.emailservice;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.cloud.context.config.annotation.RefreshScope;
import org.springframework.mail.SimpleMailMessage;
import org.springframework.mail.javamail.JavaMailSender;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RestController;

/**
 * @author zhangxuyuan
 * @version 1.0
 * @date 2021/1/14
 */
@RestController
@RefreshScope
public class EmailController {

    @Autowired
    EmailSend emailSend;
    //测试动态刷新
    @Value("${cloudservice.admin}")
    private String admin;

    @GetMapping("/email/{email}/{code}")
    public Boolean email(@PathVariable("email")String email,@PathVariable("code")String code){
       try {
           //发送邮件
           emailSend.send(email,code);
           return true;
       }catch (Exception e)
       {
           return false;
       }
    }
    //测试动态刷新
    @GetMapping("/test")
    public String test()
    {
        return this.admin;
    }

}
